package com.allwees.data.dataport.module.base.aop;

import com.allwees.bs.core.modelbase.req.Req;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * RestController拦截器
 *
 * @author yangylsky
 * @since 2019-09-23
 *
 */
@Aspect
@Component
public class RestInterceptor {
	@Pointcut("@within(org.springframework.web.bind.annotation.RestController)")
	public void pointcut() {
	}

	@Around("pointcut()")
	public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
		Object[] params = joinPoint.getArgs();
		for(Object param : params) {
			if(param == null){
				continue;
			}
			if(Req.class.isAssignableFrom(param.getClass())) {
				Req req = (Req) param;
				req.validate();
			}
		}
		return joinPoint.proceed();
	}
}
